package com.icssi.webservice.receive;

import java.io.UnsupportedEncodingException;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 * @ClassName: TransFile
 * @Description:
 * @author ICSS
 * @date 2015-1-12 下午4:10:14
 * 
 */
@WebService
public class ReceiveFile {

    protected static final Logger log = LoggerFactory.getLogger(ReceiveFile.class);

    @WebMethod
    public String ReceiveFile(@WebParam(name = "sourceOrgCode", partName = "sourceOrgCode") String sourceOrgCode, // 源应用编码
            @WebParam(name = "sourceAppCode", partName = "sourceAppCode") String sourceAppCode, // 源应用编码
            @WebParam(name = "destAppCode", partName = "destAppCode") String destAppCode, // 目标应用编码
            @WebParam(name = "dataTransType", partName = "dataTransType") String dataTransType, // 数据传输类型
            @WebParam(name = "sysTransId", partName = "sysTransId") String sysTransId, // 文件内容
            @WebParam(name = "fileName", partName = "fileName") String fileName,// 文件名称
            @WebParam(name = "fileContent", partName = "fileContent") String fileContent) {
        log.debug(
                "sourceOrgCode[{}], sourceAppCode[{}], destAppCode[{}], dataTransType[{}], sysTransId[{}], fileName[{}], fileContent[{}]",
                new Object[] { sourceOrgCode, sourceAppCode, destAppCode, dataTransType, sysTransId, fileName,
                        fileContent });
        return doPush(new WsPushParam(sourceOrgCode, sourceAppCode, destAppCode, dataTransType, sysTransId, fileName, fileContent));
    }

    /**
     * @Description:
     * @param parameterObject TODO
     */
    protected String doPush(WsPushParam parameterObject) {
        log.debug(
                "ReceiveFile:doPush:" + parameterObject.toString());
        return returnMessage("1", "success");
    }

    /**
     * 
     * @Description: WS结果返回xmls封装方法
     * @param resultCode 1成功 0失败
     * @param resultMsg 结果描述
     * @return
     */
    protected String returnMessage(String resultCode, String resultMsg) {
        StringBuffer sb = new StringBuffer();
        sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        sb.append("<Msg>");
        sb.append("<ResultCode>" + resultCode + "</ResultCode>");
        sb.append("<ResultMsg>" + resultMsg + "</ResultMsg>");
        sb.append("</Msg>");
        String result = sb.toString();
        try {
            result = new String(sb.toString().getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            log.error("returnMessage:", e.getMessage());
        }
        return result;
    }

}
